package com.cgx.tablet.beeper.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.view.View;

import com.cgx.tablet.beeper.adapter.BizTransAdapter;
import com.cgx.tablet.beeper.bean.BizTransBean;
import com.cgx.tablet.beeper.databinding.ItemBizTransBinding;
import com.yatoooon.screenadaptation.ScreenAdapterTools;

import java.util.List;


/**
 * CommunityResident
 * Created by Droven on 2017/12/23.
 */

public class BizTransViewHolder extends RecycleViewHolder<BizTransBean> implements View.OnClickListener {

    private ItemBizTransBinding mBinding;
    private BizTransAdapter.OnItemClickListener onItemClickListener;
    private List<BizTransBean> bizTransBeans;

    public BizTransViewHolder(View itemView, BizTransAdapter.OnItemClickListener onItemClickListener, List<BizTransBean> bizTransBeans) {
        super(itemView);
        mBinding = DataBindingUtil.bind(itemView);
        ScreenAdapterTools.getInstance().loadView(itemView);
        mBinding.businessRl.setOnClickListener(this);
        this.bizTransBeans = bizTransBeans;
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public void Bind(@NonNull BizTransBean bizTransBean) {
        mBinding.businessName.setText(bizTransBean.getBizName());
        mBinding.businessCb.setChecked(bizTransBean.isChecked());
    }

    @Override
    public void onClick(View view) {
        // 每次点击时，先将所有的selected设为false，并且将当前点击的item 设为true， 刷新整个视图
        if (onItemClickListener != null)
            onItemClickListener.onItemClick(view, getAdapterPosition(), bizTransBeans);
    }
}
